// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import {HOST} from './apiUrl';
// 引入的是修改后的axios
import Axios from './axios'
// 引入element ui的组件和样式
// 替换vue本来的http模块
Vue.prototype.$http = Axios
Vue.prototype.$host = HOST
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI)
Vue.config.productionTip = false

// 引入vuex
import Vuex from 'vuex'
Vue.use(Vuex)
//  实例化仓库
const store = new Vuex.Store({
  state: {
    // 一级分类id
    first_id: '',
    // 二级分类id
    second_id: ''
  },
  mutations: {
    // 修改一级分类
    setFid(state, payload) {
      state.first_id = payload
    },
    // 修改二级分类
    setSid(state, payload) {
      state.second_id = payload
    }
  },
  actions: {
    // 修改一级分类
    async getFid({commit}) {
      await commit('setFid', '621')
    },
    // 修改二级分类
    async getSid({dispatch, commit}) {
      // 先获取一级分类的数据
      await dispatch('getFid');
      // 根据一级分类的数据，获取二级分类的数据
      // await commit('setSid', )
    }
  }
})



/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
